/*
 * @Author: 陈俊健
 * @Date: 2024-10-27 22:55:39
 * @LastEditors: 陈俊健
 * @LastEditTime: 2024-10-27 22:55:56
 * @FilePath: \SlimeVR-Tracker-ESP-Mul\test\i2cscan.cpp
 * @Description: 
 * 
 * Copyright (c) 2024 by Chenjunjian, All Rights Reserved. 
 */
/* 
* i2c_port_address_scanner
* Scans ports D0 to D7 on an ESP8266 and searches for I2C device. based on the original code
* available on Arduino.cc and later improved by user Krodal and Nick Gammon (www.gammon.com.au/forum/?id=10896)
* D8 throws exceptions thus it has been left out
*
*/
#include <Arduino.h>
#include <Wire.h>

#include "ota.h"
#include "configuration/Configuration.h"
#include "helper_3dmath.h"
// #include "udpclient.h"
#include "credentials.h"
#include "defines.h"
#include "i2cscan.h"

SlimeVR::Configuration::DeviceConfig config;


void loop() {
  // otaUpdate();
  // I2CSCAN::scani2cports();

  for (uint8_t i = 0; i < 10; i++)
  {
    digitalWrite(portArray[i], HIGH);
  }
  digitalWrite(LED_PIN, HIGH);
  delay(1000);
  for (uint8_t i = 0; i < 10; i++)
  {
    digitalWrite(portArray[i], LOW);
  }
  digitalWrite(LED_PIN, LOW);
  delay(1000);
}

void setup() {
  Serial.begin(115200);
  while (!Serial);             // Leonardo: wait for serial monitor
  Wire.setClock(100000); // set I2C clock to 100kHz
  Wire.setTimeOut(150); // set I2C timeout to 150ms
  delay(1500);
  Serial.println("\n\nI2C Scanner to scan for devices on each port");
  I2CSCAN::scani2cports();
  Serial.println("Done scanning");

  pinMode(LED_PIN, OUTPUT);
  for (uint8_t i = 0; i < 10; i++)
  {
    pinMode(portArray[i], OUTPUT);
  }

  // setUpWiFi(&config);
  // otaSetup(otaPassword);
}
